package com.hsogoo.ultraman.spring;

import java.util.List;
import java.util.Map;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.hsogoo.ultraman.Config;

public class ConfigPropertySourceFactory {

    //缓存ConfigPropertySource
    private final Map<String, ConfigPropertySource> configPropertySources = Maps.newConcurrentMap();

    public ConfigPropertySource getConfigPropertySource(String name, Config source) {
        ConfigPropertySource configPropertySource = configPropertySources.get(name);
        if (configPropertySource == null) {
            configPropertySource = new ConfigPropertySource(name, source);
            configPropertySources.put(name, configPropertySource);
        }
        return configPropertySource;
    }

    public List<ConfigPropertySource> getAllConfigPropertySources() {
        return Lists.newArrayList(configPropertySources.values());
    }
}
